package com.ruipengkj.commons.util;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

public class WindowsSystemUtil {
	/** 启动windows计算器 */
	public static void StartCalculator() {
		List<String> list = new ArrayList<String>();
		list.add("calc.exe");
		ProcessBuilder pro = new ProcessBuilder(list);
		try {
			pro.start();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/** 打开浏览器 */
	@SuppressWarnings("static-access")
	public static void runBroswer(String webSite) {
		try {
			Desktop desktop = Desktop.getDesktop();// 启动已在本机桌面上注册的关联应用程序，如
													// ：浏览器，mail，print
			if (desktop.isDesktopSupported()
					&& desktop.isSupported(Desktop.Action.BROWSE)) {
				URI uri = new URI(webSite);
				desktop.browse(uri);// 默认的浏览器去打开
				// desktop.open(file) 也可以打开文件
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (URISyntaxException ex) {
			ex.printStackTrace();
		}
	}
	// 启动和关闭计算器
	// public static void startCalculator(){
	// List<String> list = new ArrayList<String>();
	// list.add("calc.exe");
	// ProcessBuilder pro = new ProcessBuilder(list);
	// try {
	// Process process = pro.start();
	// try {
	// Thread.sleep(1000);
	// process.destroy();
	// } catch (InterruptedException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// } catch (IOException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
}
